import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hook_up_rent/routes/index.dart';
import 'package:hook_up_rent/store/store.dart';

import 'widgets/bottom_tab.dart';

class Application extends StatelessWidget {
  const Application({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    FluroRouter router = FluroRouter();
    MyRoutes.configureRoutes(router);

    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.green),
      onGenerateRoute: router.generator,
      home: IndexPage(),
    );
  }
}

class IndexPage extends StatefulWidget {
  const IndexPage({Key key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final selectedIndexController = Get.put(SelectedIndexController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // obx 重新buildwidget
      body: Obx(() => tabViewList[selectedIndexController.selectIndex.value]),
      bottomNavigationBar: Obx(() => BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            items: barItemList,
            currentIndex: selectedIndexController.selectIndex.value,
            selectedItemColor: Colors.green,
            onTap: selectedIndexController.changeSelectIndex,
          )),
    );
  }
}
